package com.cskaoyan.controller.mall;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.vo.mall.KeywordListInfo;
import com.cskaoyan.bean.vo.mall.KeywordListVo;
import com.cskaoyan.service.mall.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Ajun de BBC
 * @Date 2022/7/17 13:10
 * @Version 1.5
 */

@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordService;

    @RequestMapping("list")
    public BaseRespVo keywordList(Integer page,Integer limit,String keyword,String url,String sort,String order){
        KeywordListVo keywordListVo = keywordService.keywordList(page,limit,keyword,url,sort,order);
        return BaseRespVo.ok(keywordListVo,"成功",0);
    }

    @RequestMapping("create")
    public BaseRespVo keywordCreate(@RequestBody KeywordListInfo info){
        if(info.getUrl() == null || info.getIsHot() == null || info.getIsDefault() == null){
            return BaseRespVo.ok(null,"参数不对",401);
        }
        KeywordListInfo keywordListInfo = keywordService.keywordCreate(info);
        return BaseRespVo.ok(keywordListInfo,"成功",0);
    }

    @RequestMapping("update")
    public BaseRespVo keywordUpdate(@RequestBody KeywordListInfo info){
        if(info.getUrl() == null){
            return BaseRespVo.ok(null,"参数不对",401);
        }
        keywordService.keywordUpdate(info);
        return BaseRespVo.ok(info,"成功",0);
    }

    @RequestMapping("delete")
    public BaseRespVo keywordDelete(@RequestBody KeywordListInfo info){
        keywordService.keywordDelete(info);
        return BaseRespVo.ok(info,"成功",0);
    }























}
